package com.walkline.screen;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.FontManager;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.walkline.app.NotesAppConfig;
import com.walkline.notes.NotesException;
import com.walkline.notes.NotesSDK;
import com.walkline.notes.inf.Note;
import com.walkline.notes.inf.Notes;
import com.walkline.util.Function;
import com.walkline.util.ui.ForegroundManager;
import com.walkline.util.ui.ListStyleButtonSet;

public final class NotesScreen extends MainScreen
{
	NotesSDK _notes = NotesSDK.getInstance();

	VerticalFieldManager _dealFieldManager = new VerticalFieldManager();
	ButtonField cmdGetDailyNewIdList;
	ButtonField cmdGetDealDetails;
	ButtonField cmdTestDoubleFormat;

	ForegroundManager _foreground = new ForegroundManager(0);
	ListStyleButtonSet _dealItemSet = new ListStyleButtonSet();

    public NotesScreen()
    {
    	super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT | NO_SYSTEM_MENU_ITEMS);

		try {
			FontFamily family = FontFamily.forName("BBGlobal Sans");
			Font appFont = family.getFont(Font.PLAIN, 8, Ui.UNITS_pt);
			FontManager.getInstance().setApplicationFont(appFont);
		} catch (ClassNotFoundException e) {}

		String titleIconName = Display.getWidth() < 640 ? "titleIcon_small.png" : "titleIcon_large.png";
		BitmapField bmpTitleField = new BitmapField(Bitmap.getBitmapResource(titleIconName));
		bmpTitleField.setSpace(5, 5);
		LabelField labelTitleField = new LabelField(NotesAppConfig.APP_TITLE, LabelField.ELLIPSIS);
		labelTitleField.setFont(NotesAppConfig.FONT_MAIN_TITLE);

		HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
		VerticalFieldManager vfm = new VerticalFieldManager(FIELD_VCENTER);
		vfm.add(labelTitleField);
		hfm.add(bmpTitleField);
		hfm.add(vfm);
		hfm.setBackground(NotesAppConfig.bgColor_Gradient);
		setTitle(hfm);

		HorizontalFieldManager hfmSearch = new HorizontalFieldManager(USE_ALL_WIDTH)
		{
			protected void paintBackground(Graphics g)
			{
				super.paintBackground(g);

				g.setColor(Color.GRAY);
				g.drawRect(-1, -1, getWidth() + 2, getHeight());
			}
		};
		add(_foreground);

		UiApplication.getUiApplication().invokeLater(new Runnable()
		{
			public void run()
			{
				try {
					Note note = _notes.getSingleNote(1);
					_foreground.add(new LabelField("ID: " + note.getID()));
					_foreground.add(new LabelField("Content: " + note.getContents()));
					_foreground.add(new LabelField("Post Date: " + note.getPostDate()));
					_foreground.add(new LabelField("Post Date(ms): " + note.getPostDateMS()));
					_foreground.add(new LabelField("Modify Date: " + note.getModifyDate()));
					_foreground.add(new LabelField("Modify Date(ms): " + note.getModifyDateMS()));
					_foreground.add(new LabelField("Priority: " + note.getPriority()));
					_foreground.add(new LabelField("Prgoress: " + note.getProgress()));
					_foreground.add(new LabelField("Is Deleted: " + note.isDeleted()));
				} catch (NotesException e) {Function.errorDialog(e.toString());}

				//try {
				//	Notes notes = _notes.getNotes();
				//} catch (NotesException e) {Function.errorDialog(e.toString());}
			}
		});
	}

    protected boolean onSavePrompt() {return true;}
}